import type {
    AxiosRequestConfig,
    AxiosResponse,
    InternalAxiosRequestConfig,
    Method,
    AxiosRequestHeaders
} from 'axios';

export type Result<T = any> = {
    code: number;
    success: boolean;
    msg: string;
    data?: T;
    name?: string;
    type?: string;
};

// 定义接口
export type PendingType = {
    url?: string;
    method?: Method | string;
    params: any;
    data: any;
    cancel: any;
};

export type QsRequestHeaderType = {
    hideLoading?: 0 | 1 | '0' | '1';
    loadingTarget?: string;
};

export interface QsInternalAxiosRequestConfig<D = any> extends AxiosRequestConfig<D> {
    headers?: QsRequestHeaderType | AxiosRequestHeaders;
}

export interface QsRequestInterceptors<T = any> {
    requestInterceptor: (
        config: InternalAxiosRequestConfig
    ) => InternalAxiosRequestConfig | Promise<InternalAxiosRequestConfig>;
    requestInterceptorCatch: (err: any) => any;
    responseInterceptor: (res: AxiosResponse<Result<T>>) => Promise<AxiosResponse<Result<T>>>;
    responseInterceptorCatch: (err: any) => any;
}

// 创建一个新的接口继承自AxiosRequestConfig
export interface QsRequestConfig extends AxiosRequestConfig {
    [key: string]: any;
    interceptors: QsRequestInterceptors;
}
